import { EntityState, EntityStore, PaginatorPlugin, QueryEntity, StoreConfig } from '@datorama/akita';
import { produce } from 'immer'; 
import { VISIBILITY_FILTER } from "@/models/commonType";
import { AnchorsItem } from '@/models/request/userReq';

export interface AnchorFollowEntity extends EntityState<AnchorsItem, string> {
  filter: VISIBILITY_FILTER;
}

@StoreConfig({ name: "anchor_follows", producerFn: produce, idKey: 'to_user_id' })
export class AnchorFollowStore extends EntityStore<AnchorFollowEntity> {
  constructor() {
    super({
      filter: VISIBILITY_FILTER.SHOW_ALL,
    });
  }
}

export class AnchorFollowQuery extends QueryEntity<AnchorFollowEntity> {
  filter$ = this.select((state) => state.filter);

  constructor(protected store: AnchorFollowStore) {
    super(store);
  }
}

export const makeStore = (): [AnchorFollowStore, AnchorFollowQuery, PaginatorPlugin<AnchorFollowEntity>] => {
  const store = new AnchorFollowStore();
  const query = new AnchorFollowQuery(store);

  const anchor_follows_paginator = new PaginatorPlugin(query)
    .withControls()
    .withRange();

  return [store, query, anchor_follows_paginator];
};
